import service from '@/utils/request'
import { getLoginType  } from "@/utils/auth";

const LoginApi = {
  loginByUsername:function(data){
    return service.post('admin/login', data);
  },
  sysUserLoginOut: function () {
    return service.post('admin/loginOut');
  },
  getUserInfoByToken: function (token) {
    const data = {token: token}
    return service.post('admin/getInfoByToken', data);
  },
  roleInfoList(data){
    // 根据角色类别和细分角色查询对应user的IdName集合
    return service.get('user/listIdName', {params:data});
  },
  fastLogin(data){
    return service.post('admin/fastLogin', data);
  },
  salesmanList(data){
    return service.get('salesman/listIdName', {params:data});
  },
  // :fixme User Exit Logout 🎃
  logout:function(){
    if(getLoginType() === 'cas') {
      return service.delete(`auth_proxy/token/logout`, { shenyuContextPath: process.env.VITE_API_URL});
    } else {
     return service.delete(`token/logout`, { shenyuContextPath: process.env.VITE_AUTH_URL});
    }
  },
  // 获取用户列表
  getUserList:function(data){
    return service.get('userRelation/listIdName', {params:data});
  },
  // 获取租户列表
  getTenantList:function(data){
    return service.get('userTenant/listRelationData', {params:data});
  },
  // 切换用户
  switchUser:function(data){
    return service.post('user/changeUserAccount?userId='+data);
  },
  // 切换租户
  switchTenant:function(data){
    return service.get('user/changeTenant/'+data);
  },
  batchSetRelation:function(data){
    return service.post('userRelation/batchSetRelation', data);
  },
  batchSetRelationTenant:function(data){
    return service.post('userTenant/batchSetRelation',data);
  },
  listRelationData:function(data){
    return service.get('userRelation/listRelationData', {params:data});
  },
  listRelationTenantData:function(data){
    return service.get('userTenant/listRelationData', {params:data});
  },


}

export default LoginApi
